package B刷题.二叉树;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

/**
 * @author wei.zhao
 * @description: 94.二叉树的中序遍历
 * @date 2022年11月09日 16:05
 */
public class Code02_InorderTraversal {

    public List<Integer> inorderTraversal(TreeNode root) {
        ArrayList<Integer> result = new ArrayList<>();
        Stack<TreeNode> stack = new Stack<>();
        while (!stack.isEmpty() || root != null) {
            if (root != null) {
                stack.add(root);
                root = root.left;
            } else {
                TreeNode pop = stack.pop();
                result.add(pop.val);
                root = pop.right;
            }
        }
        return result;
    }

}
